home *** CD-ROM | disk | FTP | other *** search
- Path: noc.netcom.net!news
- From: Sean Palmer <sean@delta.com>
- Newsgroups: comp.lang.c++,comp.lang.c,comp.os.msdos.programer,comp.os.ms-windows.programmer.misc
- Subject: Re: fastest code
- Date: Tue, 09 Apr 1996 15:28:22 -0400
- Organization: deltaComm Development, Inc.
- Message-ID: <316ABA56.3A68@delta.com>
- References: <316112A2.7D37@public.sta.net.cn> <31611AC9.7DE1@wight.hursley.ibm.com> <3162c21a.6084138@204.248.25.97> <31641DE2.31D4@halcyon.com> <31658942.99299605@204.248.25.97> <4k9g04$4ov@news1.mnsinc.com>
- NNTP-Posting-Host: landspeeder.delta.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 3.0B2 (Win95; I)
-
- > : The original question was looking for this kind of information (even
- > : if the poster does not understand Big-O, which I don't know if he did
- > : or not). He wants to know what compiler will best optimize the
- > : machine language code generated for a specific OS and computer
- > : architecture.
- >
- > Optimizations have little to do with time complexities as well. A
- > compiler today is not likely to change an O(n^2) algorithm into an
- > O(n) algorithm simply by optimizing the code, though an O(n) algorithm
- > might be optimized into an O(1) algorithm if you're talking about a
- > truly dumb programmer ;).
-
- Being dumb aside, if the (fictitious bad) compiler, for this C++ code:
-
- void test(int& x) {
- if (!(x==0))
- x=x+1;
- }
-
- generates the following x86 asm code:
-
- test@i:
- push esi
- push edi
- push ebp
- mov ebp,esp
- push eax
- push ebx
-
- mov eax,[x]
- mov ebx,[eax]
- cmp ebx,0
- jz @@loc2
- jmp @@loc1
- @@loc2:
- mov eax,[x]
- mov ebx,[eax]
- add ebx,1
- mov eax,[x]
- mov [x],ebx
- @@loc1:
-
- pop ebx
- pop eax
- pop ebp
- pop edi
- pop esi
- ret
-
- while another compiler generates this code:
-
- test@i:
- mov ebx,[eax]
- test ebx,ebx
- jnz @@loc1
- inc dword ptr [eax]
- @@loc1:
- ret
-
-
- which would you rather call in a 10000-iteration loop?
-
- The difference, is that the first one would force you (if writing a
- video game for instance) to code 30% of the game in assembly language
- to get the necessary speed, where the second compiler would allow you to
- code 90% of the game in good ol' readable, maintainable, portable C++...
- because writing in assembler wouldn't get you a noticeable speed gain.
-
- Sure, a good optimizer isn't going to fix a bad algorithm. But a bad
- optimizer will sure slow down a good algorithm...
-
- Take Borland vs. Watcom for instance. Borland has a hideous code
- generator. Watcom's makes code that's often faster than what I would
- write. It looks wierd, but it's fast.
-
- Borland won't even inline functions that contain loops or switch
- statements. It even balks on complicated if statements. Watcom has no
- such restriction.
-